<?php

namespace StudyBuddy;

/**
 * abstract class representing submitted answer
 * concrete class must implement all methods
 *
 */
abstract class SubmittedAnswer extends StudyBuddyObject {

    protected $oUser;
    protected $oBody;

    /**
     * Get object of type User of user
     * who posted the answer
     *
     * @return object of type User
     */
    abstract public function getUserObject();

    /**
     * @return object of type Utf8String representing
     * the body of the answer
     */
    abstract public function getBody();

    /**
     * @return string ip address from where
     *
     * the answer was submitted
     */
    abstract public function getIP();

    /**
     * @return int id of question for which
     * this answer is submitted
     */
    abstract public function getQid();

    /**
     * Concrete class may override this to provide
     * array of data that should be added to answer data
     * array from which the question object Question
     * is created.
     *
     * @return associative array
     */
    public function getExtraData() {

        return array();
    }

    /**
     * Get name of app used for submitting
     * this question
     * @return string
     */
    public function getApp() {
        return '';
    }

    /**
     * Get id of app used for submitting
     * this question
     * @return null
     */
    public function getAppId() {
        return null;
    }

    /**
     * Get id of link to app used for submitting
     * this question
     *
     * @return null
     */
    public function getAppLink() {
        $name = $this->getApp();
        $id = $this->getAppId();

        return (!empty($id) && !empty($name)) ? \sprintf('<a href="/app/%s" rel="nofollow" target="_blank">%s</a>', $id, $name) : null;
    }

}
